<template>
  <div class="aa-container" style="padding-top: 20px;">
    <div class="flex-row" v-for="(item, index) in participants" :key="item.uuid">
      <div class="material-textfield green w-25"  style="margin-right: 10px;" :class="{'validate-err': errors.has('participants_name_' + index)}" >
        <input type="text" required v-model="item.name" v-validate="'required|max:10'" :data-vv-name="'participants_name_' + index" >
        <label data-content="名称*"></label>
      </div>
      <div class="material-textfield green w-25"  style="margin-right: 10px;" :class="{'validate-err': errors.has('participants_phone_' + index)}">
        <input type="text" required v-model="item.phone" v-validate="'required|fax'" :data-vv-name="'participants_phone_' + index"/>
        <label data-content="联系方式*"></label>
      </div>
      <div class="material-textfield green flex-all"  style="margin-right: 10px;" >
        <input type="text" required v-model="item.remark" >
        <label data-content="备注"></label>
      </div>
      <i class="el-icon-delete delete-info" @click="deleteItem(item, index)" v-show="!item.ctime && participants.length > 1"></i>
    </div>
    <div class="add-info" @click="addItem()" v-show="participants[0] && !participants[0].ctime">
      <i class="el-icon-plus"></i>
      <span>添加</span>
    </div>
  </div>
</template>

<script>
  export default {
    title: '参会人员信息',
    name: 'participants-info',
    data () {
      return {
        participants: [],
      }
    },
    props: {
      data: {}
    },
    mounted () {
      this.participants = this.data
      if (this.participants.length === 0) {
        this.addItem()
      }
    },
    methods: {
      addItem () {
        this.participants.push({
          name: '',
          phone: '',
          remark: '',
          isSign: 'NO'
        })
      },
      deleteItem (item, index) {
        this.participants.splice(index, 1)
      },
      validate () {
        return this.$validator.validateAll()
      }
    },
    watch: {
      'participants': {
        handler: function (val, oldVal) {
          this.$emit('update:data', this.participants)
        },
        deep: true
      },
      'data': {
        handler: function (val, oldVal) {
          this.participants = val
        },
        deep: true
      }
    }
  }
</script>
